******************************************************************************
* Figure H.3: Google Trend Plot
******************************************************************************

capture cd "$datadir/googlesearch_cashindia/"

	local names 2000Rs atmline ATMCashWithDrawalLimitToday cash ATMnearMeWithCash AuthorityLetterForCashDeposit	
	local n=1
	
	foreach name in `names' {
	
	import delimited `name'.csv, clear
	drop in 1/2
	rename v1 week_temp
	rename v2 index
	
	gen year=substr(week_temp,1,4)
	gen month=substr(week_temp,6,2)
	gen date=substr(week_temp,9,2)

	destring year month date index, replace
	
	gen week=mdy(month,date,year)
	format week %td
	
	keep index week
	
	if "`name'"=="2000Rs"{
		local x 2000 Rs
	}
	
	if "`name'"=="ATMCashWithDrawalLimitToday"{
		local x ATM Cash Withdrawal Limit Today
	}
	
	if "`name'"=="atmline"{
		local x ATM Line
	}
	
	if "`name'"=="ATMnearMeWithCash"{
		local x ATM Near Me With Cash
	}
	
	if "`name'"=="AuthorityLetterForCashDeposit"{
		local x Authority Letter for Cash Deposit
	}
	
	
	if "`name'"=="cash"{
		local x Cash
	}
	
	tsset week
	tsfill
	
	gen month=mofd(week)
	format month %tm
	
	gen base=0
	gen highlight=0
	replace highlight=100 if month==mofd(mdy(11,1,2016))
	replace highlight=100 if month==mofd(mdy(12,1,2016))
	replace highlight=100 if month==mofd(mdy(1,1,2017))
	
	twoway rbar highlight base week, color(gs11) lcolor(gs12) || tsline index, title("`x'", pos(12)) xtitle("") ytitle("") ylab(,nogrid)  legend(off) graphregion(fcolor(white)) plotregion(lcolor(black)) lc(black) nodraw
	graph save `n', replace
	
	local n=`n'+1
	
	}
	
	graph combine "1.gph" "2.gph" "3.gph" "4.gph" "5.gph" "6.gph", xsize(12) ysize(5) graphregion(fcolor(white))
	graph export "$outputdir_fig\Figure_H_3.pdf", as(pdf) replace
	
	forvalues i =1/6{
		capture rm "`i'.gph"
	}

	
/*
	
capture cd "$superdir/Data/newspaper/"
	
	
	****** Data from newspaper articles search
	
	import delimited news_trends.csv, clear
	drop if substr(title,1,6) == "FE1000"
	drop if substr(title,1,7) == "FE 1000"
	keep source term date

	g count = 1 
	
	rename date date_pq
	
	gen year=substr(date_pq,1,4)
	gen month=substr(date_pq,6,2)
	gen date=substr(date_pq,9,2)
	
	
	destring year month date, replace
	
	collapse (sum) count, by(year month date term) 
	
	gen week=mdy(month,date,year)
	format week %td
	
	bys term: egen maxcount = max(count)
	replace count = count*100/maxcount
	keep count week term
	
	
	forval i=0/5{
	
	preserve
		
		keep if term == `i'
		tsset week
		tsfill
		
		gen month=mofd(week)
		format month %tm
		
				
		if `i' == 0 {
			local x 2000 Rs
		}
		
		if `i' == 1{
			local x ATM Line
		}
		
		if `i' == 2{
			local x ATM Cash Withdrawal Limit Today
		}
		
		if `i' == 3{
			local x Cash
		}
		
		
		if `i' == 4{
			local x ATM Near Me With Cash
		}
		
		if `i' == 5{
			local x Authority Letter for Cash Deposit
		}
		
		gen base=0
		gen highlight=0
		replace highlight=100 if month==mofd(mdy(11,1,2016))
		replace highlight=100 if month==mofd(mdy(12,1,2016))
		replace highlight=100 if month==mofd(mdy(1,1,2017))
		
		local j = `i'+1
		*twoway rbar highlight base week, color(gs11) lcolor(gs12) || tsline index, title("`x'", pos(12)) xtitle("") ytitle("") label(Sep16 Oct16 Nov16 Dec16 Jan17 Feb17 Mar17 Apr17 May17 Jun17 Jul17, angle(45)) legend(off) graphregion(fcolor(white)) plotregion(lcolor(black)) lc(black)
		twoway rbar highlight base week, color(gs11) lcolor(gs12) || tsline count, title("`x'", pos(12)) xtitle("") ytitle("") ylab(,nogrid)  legend(off) graphregion(fcolor(white)) plotregion(lcolor(black)) lc(black) nodraw
		graph save `j', replace
		
	restore	
	}
	
	
	graph combine "1.gph" "2.gph" "3.gph" "4.gph" "5.gph" "6.gph", xsize(12) ysize(5) graphregion(fcolor(white))
	*Note that xsize=12 here is to make it long enough for key word "CashWithDrawalLimitFromSavingsAccount"
	graph export "$superdir\Draft\Figures\newspaper_trends.pdf", as(pdf) replace
	
	forvalues i =1/6{
		capture rm "`i'.gph"
	}

*/
